#include "cCheckbox.h"
#include <Uxtheme.h>
cCheckbox::cCheckbox(cHwnd * hwndParent,LPCSTR label,int x,int y,int largeur,int hauteur,cHwnd * HWNDParent):
    cControl(hwndParent)
{
     //ctor
     HWND leParent=hwndParent->getHwnd();
    if(HWNDParent!=NULL)
        leParent=HWNDParent->getHwnd();

    hWnd=CreateWindow("BUTTON", label, WS_CHILD | BS_AUTOCHECKBOX | WS_VISIBLE | WS_TABSTOP ,
                      x, y, largeur, hauteur,  hwndParent->getHwnd(), NULL, hInstance, NULL);
    FinalInit();

    onClick=NULL;
}

cCheckbox::~cCheckbox()
{
    //dtor
}

string cCheckbox::GetText()
{
    int longueur=Button_GetTextLength(hWnd)+1;
    char * texte=new char[longueur];
    Button_GetText(hWnd,texte,longueur);
    string retour=texte;
    delete(texte);
    return retour;
}

void cCheckbox::SetText(string texte)
{
    Button_SetText(hWnd,texte.c_str());
}

void cCheckbox::SetChecked(bool check)
{
    if(check)
        Button_SetCheck(hWnd,BST_CHECKED);
    else
        Button_SetCheck(hWnd,BST_UNCHECKED);
}

bool cCheckbox::GetChecked()
{
    if(Button_GetCheck(hWnd)==BST_CHECKED)
        return true;
    else
        return false;
}



bool cCheckbox::TraitementEvent(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,LRESULT &resultat)
{
    switch(message)
    {
        case WM_ERASEBKGND:
        {

            break;
        }

        case WM_COMMAND:
        {
            switch (HIWORD(wparam))
            {
            	case BN_CLICKED:
            	{
                    if(onClick)
                    {
                        cEvent * event=new cEvent(this);
                        (_parent->*onClick)(event);
                        delete event;
                        resultat=0;
                        return true;
                    }

            		break;
                }
            };

            break;
        }
        case WM_CTLCOLORSTATIC:
        {
            HDC texthdc = (HDC) wparam;


            //if(this->_transparence)
            SetBkMode ( texthdc, TRANSPARENT );
            //SelectObject(texthdc, hbr);
            //SetTextColor( texthdc, RGB(255, 0, 0));

            HBRUSH hbr = (HBRUSH)GetStockObject( NULL_BRUSH );
            //if(this->_transparence)
            resultat=(LRESULT)hbr;
            return true;
            break;
        }
    };
    return false;
}

